﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;

namespace EF.Oracle.Sql
{

 

 
    class Program
    {
        static void Main(string[] args)
        {
            //连接Oracle
            using (var db = new OracleDbContext())
            {
                var categories = new List<Category>
                {
                    new Category(){ CategoryId = Guid.NewGuid().ToString().ToUpper(),CategoryName="Mobile",Description="手机大类"},
                    new Category(){ CategoryId = Guid.NewGuid().ToString().ToUpper(), CategoryName="Computer",Description="电脑大类"}
                };

                //AddOrUpdate:根据指定列,相同就更新,不相同就添加
                categories.ForEach(list => db.Categories.AddOrUpdate(c => c.CategoryId, list));
                db.SaveChanges();

                //var query = db.Categories;
                var query = from c in db.Categories select c;

                //遍历输出
                foreach (var item in query)
                {
                    Console.WriteLine("类别:{0};说明:{1}", item.CategoryName, item.Description);
                }
            }


            using (var db = new SqlServerDbContext())
            {
                var categories = new List<Category>
                {
                    new Category(){ CategoryId = Guid.NewGuid().ToString().ToUpper(),CategoryName="Mobile",Description="手机大类"},
                    new Category(){ CategoryId = Guid.NewGuid().ToString().ToUpper(), CategoryName="Computer",Description="电脑大类"}
                };

                //AddOrUpdate:根据指定列,相同就更新,不相同就添加
                categories.ForEach(list => db.Categories.AddOrUpdate(c => c.CategoryId, list));
                db.SaveChanges();

                //var query = db.Categories;
                var query = from c in db.Categories select c;

                //遍历输出
                foreach (var item in query)
                {
                    Console.WriteLine("类别:{0};说明:{1}", item.CategoryName, item.Description);
                }
            }
            Console.ReadKey();
        }


    }
}
